package com.example.mysqldemo.Mapper;

import com.example.mysqldemo.ArticleInfo;
import com.example.mysqldemo.UserInfo;
import org.apache.ibatis.annotations.*;

import java.util.List;
@Mapper
public interface UserInfoMapper {
    @Select("select * from userinfo")
    public List<UserInfo> querAlluser();
    @Select("select * from userinfo where id = 1")
    UserInfo querAlluser2();
    @Select("select * from userinfo where id = #{id}")
    UserInfo querAlluser3(Integer id);
    @Insert("insert into userinfo (username,password,age,gender,phone)values('admin','admin',18,1,'12345678912')")
    Integer insertInto();
    @Insert("insert into userinfo (username ,password,age,gender,phone,delete_flag)values (#{username},#{password},#{age},#{gender},#{phone},#{deleteFlag})")
    Integer insertInto2(UserInfo userInfo);
    @Update("update userinfo set phone='11111111111' where username='zhangsan'")
    Integer updatebook();
    @Options(useGeneratedKeys = true,keyColumn = "id")
    @Insert("insert into userinfo (username ,password,age,gender,phone,delete_flag)values (#{username},#{password},#{age},#{gender},#{phone},#{deleteFlag})")
    Integer insertInto3(UserInfo userInfo);
    @Delete("delete  from userinfo where id = #{id}")
    void delete(Integer id);
    @Select("select id,username,password,age,gender,phone,delete_flag as deleteFlag," +
            "create_time as createTime,update_time as updateTime from userinfo")
    List<UserInfo> queryAllUser5();
    @Select("select * from userinfo")
    @Results(id = "resultMap",value = {
            @Result(column = "delete_flag",property = "deleteFlag"),
            @Result(column = "create_time",property = "createTime")
    })
    List<UserInfo> queryAllUser6();

    @Select("select id,username,password,age,gender,phone,delete_flag," +
            "create_time,update_time from userinfo where id = #{userid}")
    @ResultMap(value = "resultMap")
    UserInfo queryAllUser7(@Param("userid") Integer id);

    @Select("select * from userinfo,articleinfo where userinfo.id=articleinfo.uid and userinfo.id=1")
    @Results(id = "resultMap11",value = {
            @Result(column = "delete_flag",property = "deleteFlag"),
            @Result(column = "create_time",property = "createTime"),
            @Result(column = "update_time",property = "updateTime")
    })
    ArticleInfo queryUserByUid(Integer id);

    @Select("select * from userinfo where username='${name}'")
    UserInfo querySelectbig(String name);

    @Select("select id, username, age, gender, phone, delete_flag, create_time, update_time " +
            "from userinfo order by id #{sort} ")
    List<UserInfo> queryAllUserBySort(String sort);



}
